angular.module('Controller')

.controller 'LoginCtrl', ($scope, $state,cryptUtil,commonUtil,userData,$localStorage,commonConstant,wfAlert,$http) ->
    $scope.$storage = $localStorage
    _.extend $scope,
        loginType:0
        data:
            account:''
            username:''
            password:''
        changeLoginType:(i)->
            console.log i
            $scope.loginType = i
        login:->
            if $scope.data.username=='' or $scope.data.username==undefined
                $scope.data.username='yy7721869'
                $scope.data.password='7721869'
            postData={
                account:'pkcrm'
                phone:$scope.data.username
                password:cryptUtil.hex_md5($scope.data.password)
            }
            $http.post("/wechat/member/login/phone",postData)
            .success((resp)->
                console.log(resp)
                if resp.code==0
                    user=angular.copy resp.message
                    userData.setUser user
                    userData.setToken resp.message.token
                    $state.go 'myself'
                else
                    wfAlert.toastError(resp.message)
            )


        goRegister:->
            $state.go 'register'


